//
// Decompiled by Jadx - 503ms
//
package fn;

import a.g;
import a.i;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.text.TextUtils;
import de.robv.android.xposed.XposedHelpers;
import fm.b;
import gc.ac;
import gc.ag;
import gc.ap;
import gc.ce;
import gc.cv;
import gc.z;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import me.plusne.GreenDao.dao.ChatLogDao;
import me.plusne.GreenDao.dao.LookHomeJsonDao;
import me.plusne.common.Json.JsonHookStatic;
import me.plusne.common.Json.Soul.JsonHomepage;
import me.plusne.common.Json.Soul.JsonHookDownPostMessage;
import me.plusne.common.Json.Soul.JsonOnlineState;
import me.plusne.common.Json.Soul.JsonSoulAutoMessage;
import me.plusne.common.Json.Soul.JsonSoulPlanet;
import me.plusne.common.Json.Soul.SoulSendMessageJson;
import org.json.JSONObject;
import r.f;

public final class p extends HandlerThread implements Handler.Callback {
    public static final int a = 0;
    public final LinkedList b;
    public final LinkedList c;
    public boolean d;
    public boolean e;

    static {
        new ArrayList();
    }

    public p() {
        super("myHandler");
        this.b = new LinkedList();
        this.c = new LinkedList();
        this.d = false;
        this.e = false;
    }

    public static void f(JsonHomepage jsonHomepage, boolean z, int i) {
        for (JsonHomepage.DataDTO.PostListDTO postListDTO : jsonHomepage.getData().getPostList()) {
            long id = postListDTO.getId();
            if (i != 1) {
                if (i != 2) {
                    if (i == 3 && postListDTO.getAttachments() != null) {
                        for (JsonHomepage.DataDTO.PostListDTO.AttachmentsDTO attachmentsDTO : postListDTO.getAttachments()) {
                            long id2 = attachmentsDTO.getId();
                            if ("VIDEO".equals(attachmentsDTO.getType())) {
                                String fileUrl = attachmentsDTO.getFileUrl();
                                if (!TextUtils.isEmpty(fileUrl)) {
                                    g.c(y.by.getActivity(), fileUrl, "video_" + id2 + ".mp4");
                                    if (z) {
                                        f i2 = f.i();
                                        i2.g = 0;
                                        i2.h = false;
                                        i2.k();
                                        i2.l("[" + id + "]  ->  已添加下载任务");
                                    }
                                }
                            }
                        }
                    }
                } else if (postListDTO.getAttachments() != null) {
                    for (JsonHomepage.DataDTO.PostListDTO.AttachmentsDTO attachmentsDTO2 : postListDTO.getAttachments()) {
                        long id3 = attachmentsDTO2.getId();
                        if ("IMAGE".equals(attachmentsDTO2.getType())) {
                            String fileUrl2 = attachmentsDTO2.getFileUrl();
                            if (!TextUtils.isEmpty(fileUrl2)) {
                                g.c(y.by.getActivity(), fileUrl2, id3 + ".png");
                                if (z) {
                                    f i3 = f.i();
                                    i3.g = 0;
                                    i3.h = false;
                                    i3.k();
                                    i3.l("[" + id + "]  ->  已添加下载任务");
                                }
                            }
                        }
                    }
                }
            } else {
                ac acVar = new ac();
                acVar.de("https://post.soulapp.cn/v3/post/praise?postId=" + id + "&type=0", new HashMap(), "POST");
                acVar.dg(new l(z, id));
            }
        }
    }

    public static void g(JsonOnlineState jsonOnlineState) {
        if (jsonOnlineState.getMsgState() == 0) {
            String str = z.do(jsonOnlineState.getFrom());
            ac.dc("cn.soulapp.android.component.home.api.user.user.IUserApi", "USER", "getUserInfo", new fg.f(13, jsonOnlineState, str), new Object[]{str, "", Boolean.TRUE});
            return;
        }
        JsonHookStatic jsonHookStatic = y.by;
        LookHomeJsonDao lookHomeJsonDao = jsonHookStatic.getDb().u;
        lookHomeJsonDao.getClass();
        g gVar = new g(lookHomeJsonDao);
        gVar.l(LookHomeJsonDao.Properties.From.f(jsonOnlineState.getFrom()), new i[]{LookHomeJsonDao.Properties.To.f(jsonOnlineState.getTo())});
        gVar.i(1);
        fm.g gVar2 = (fm.g) gVar.k();
        if (gVar2 != null) {
            gVar2.g = System.currentTimeMillis();
            jsonHookStatic.getDb().l(gVar2);
            if (j.ae("showLookHome")) {
                jsonHookStatic.getMainHandler().post(new k(gVar2, 0));
            }
        }
    }

    /* JADX WARN: Failed to find 'out' block for switch in B:2:0x0014. Please report as an issue. */
    public static void h(JsonSoulAutoMessage jsonSoulAutoMessage) {
        ac acVar;
        m mVar;
        ag agVar;
        n nVar;
        HashMap hashMap = new HashMap();
        switch (jsonSoulAutoMessage.getType()) {
            case 1:
                acVar = new ac();
                acVar.de("https://post.soulapp.cn/v3/post/praise?postId=" + jsonSoulAutoMessage.getPostId() + "&type=0", hashMap, "POST");
                mVar = new m(jsonSoulAutoMessage, 0);
                acVar.dg(mVar);
                return;
            case 2:
                hashMap.put("userIdEcpt", jsonSoulAutoMessage.getAuthorIdEcpt());
                acVar = new ac();
                acVar.de("https://api-user.soulapp.cn/v2/follow/users", hashMap, "POST");
                mVar = new m(jsonSoulAutoMessage, 1);
                acVar.dg(mVar);
                return;
            case 3:
                hashMap.put("content", jsonSoulAutoMessage.getText());
                hashMap.put("postId", Long.valueOf(jsonSoulAutoMessage.getPostId()));
                hashMap.put("state", "NORMAL");
                acVar = new ac();
                acVar.de("https://post.soulapp.cn/posts/comments/add", hashMap, "JSON");
                mVar = new m(jsonSoulAutoMessage, 2);
                acVar.dg(mVar);
                return;
            case 4:
                String dm = z.dm(jsonSoulAutoMessage.getAuthorIdEcpt());
                if (b.e(10, dm) != null) {
                    return;
                }
                String cf = y.cf("sendGiftJson", "");
                if (TextUtils.isEmpty(cf)) {
                    return;
                }
                z.ek(dm, cf);
                b.k(dm, 10, cf, "");
                ap.dc++;
                j.bi(new Object[]{"[" + jsonSoulAutoMessage.getSignature() + "]已发送礼物"});
                return;
            case 5:
                String dm2 = z.dm(jsonSoulAutoMessage.getAuthorIdEcpt());
                if (b.e(13, dm2) != null) {
                    return;
                }
                b.k(dm2, 13, "", "");
                hashMap.put("targetUserIdEcpt", jsonSoulAutoMessage.getAuthorIdEcpt());
                agVar = new ag();
                agVar.ct(y.cj("bgImgOnline"), hashMap, "POST");
                nVar = new n(jsonSoulAutoMessage, dm2, 0);
                agVar.cv(nVar);
                return;
            case 6:
                String dm3 = z.dm(jsonSoulAutoMessage.getAuthorIdEcpt());
                if (b.e(14, dm3) != null) {
                    return;
                }
                b.k(dm3, 14, "", "");
                hashMap.put("userIdEcpt", jsonSoulAutoMessage.getAuthorIdEcpt());
                agVar = new ag();
                agVar.ct(y.cj("invitePost"), hashMap, "POST");
                nVar = new n(jsonSoulAutoMessage, dm3, 1);
                agVar.cv(nVar);
                return;
            case 7:
                String dm4 = z.dm(jsonSoulAutoMessage.getAuthorIdEcpt());
                if (b.e(15, dm4) != null) {
                    return;
                }
                b.k(dm4, 15, "", "");
                ag.cs("cn.soulapp.android.component.chat.api.ChatAPI", "USER", "reportMessage", new ce(18), new Object[]{"1", jsonSoulAutoMessage.getAuthorIdEcpt(), y.cf("BIBI_TRIGGER", ""), Long.valueOf(y.ce(0L, "BIBI_TRIGGER_TIME"))});
                return;
            case 8:
                String dm5 = z.dm(jsonSoulAutoMessage.getAuthorIdEcpt());
                if (b.e(16, dm5) != null) {
                    return;
                }
                b.k(dm5, 16, "", "");
                try {
                    Object bl = j.bl("cn.soulapp.imlib.msg.chat.JsonMsg", new Object[]{y.cj("speedPush")});
                    XposedHelpers.setObjectField(bl, "content", y.cf("LoveSpeedText", "您使用奇遇铃加速卡匹配成功"));
                    z.ep(z.dx(35, bl, dm5));
                    ArrayList arrayList = ap.cp;
                    return;
                } catch (Exception e) {
                    ArrayList arrayList2 = ap.cp;
                    e.printStackTrace();
                    return;
                }
            default:
                return;
        }
    }

    /* JADX WARN: Failed to find 'out' block for switch in B:2:0x001d. Please report as an issue. */
    public static void i(JsonSoulPlanet jsonSoulPlanet) {
        ag agVar;
        o oVar;
        String userId = jsonSoulPlanet.getUserId();
        HashMap hashMap = new HashMap();
        switch (jsonSoulPlanet.getType()) {
            case 1:
                if (b.e(10, jsonSoulPlanet.getUserId()) != null) {
                    j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已有发送记录 ->礼物"});
                    return;
                }
                String cf = y.cf("sendGiftJson", "");
                if (TextUtils.isEmpty(cf)) {
                    return;
                }
                try {
                    z.ek(jsonSoulPlanet.getUserId(), cf);
                    cv.a++;
                } catch (Exception e) {
                    e.printStackTrace();
                    cv.b++;
                }
                b.k(jsonSoulPlanet.getUserId(), 10, cf, "");
                j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已发送礼物"});
                return;
            case 2:
                if (b.e(13, userId) != null) {
                    j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已有发送记录 ->擦灰"});
                    return;
                }
                b.k(userId, 13, "", "");
                hashMap.put("targetUserIdEcpt", jsonSoulPlanet.getUserIdEcpt());
                agVar = new ag();
                agVar.ct(y.cj("bgImgOnline"), hashMap, "POST");
                oVar = new o(jsonSoulPlanet, userId, 0);
                agVar.cv(oVar);
                return;
            case 3:
                if (b.e(15, userId) == null) {
                    b.k(userId, 15, "", "");
                    ag.cs("cn.soulapp.android.component.chat.api.ChatAPI", "USER", "reportMessage", new ce(19), new Object[]{"1", jsonSoulPlanet.getUserIdEcpt(), y.cf("BIBI_TRIGGER", ""), Long.valueOf(y.ce(0L, "BIBI_TRIGGER_TIME"))});
                    return;
                } else {
                    j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已有发送记录 ->哔哔机"});
                    return;
                }
            case 4:
                if (b.e(14, userId) != null) {
                    j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已有发送记录 ->邀请瞬间"});
                    return;
                }
                b.k(userId, 14, "", "");
                hashMap.put("userIdEcpt", jsonSoulPlanet.getUserIdEcpt());
                agVar = new ag();
                agVar.ct(y.cj("invitePost"), hashMap, "POST");
                oVar = new o(jsonSoulPlanet, userId, 1);
                agVar.cv(oVar);
                return;
            case 5:
                if (b.e(16, userId) != null) {
                    j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已有发送记录 ->加速卡"});
                    return;
                }
                b.k(userId, 16, "", "");
                try {
                    Object bl = j.bl("cn.soulapp.imlib.msg.chat.JsonMsg", new Object[]{y.cj("speedPush")});
                    XposedHelpers.setObjectField(bl, "content", y.cf("LoveSpeedText", "您使用奇遇铃加速卡匹配成功"));
                    z.ep(z.dx(35, bl, userId));
                    cv.j++;
                    return;
                } catch (Exception e2) {
                    e = e2;
                    cv.j++;
                    e.printStackTrace();
                    return;
                }
            case 6:
                if (b.e(18, userId) != null) {
                    j.bi(new Object[]{"[" + jsonSoulPlanet.getSignature() + "]已有发送记录 ->加速卡"});
                    return;
                }
                b.k(userId, 18, "", "");
                Object bl2 = j.bl("cn.soulapp.imlib.msg.chat.JsonMsg", new Object[]{"little_tip"});
                String as = j.as(bl2, "content");
                try {
                    JSONObject jSONObject = TextUtils.isEmpty(as) ? new JSONObject() : new JSONObject(as);
                    jSONObject.put("url", y.cf("planetPostLink", "https://w13.soulsmile.cn/activity/#/verify-label/progress?targetUserId=bGZ1MGtWNU1lZnZWVlgvZUh1NEExdz09&authId=1241&bussiness=20000"));
                    jSONObject.put("urlText", y.cf("planetPostTitle", "帮Ta进行引力认证吧,可以获得更多好物"));
                    jSONObject.put("type", "LUCKY_STAR");
                    j.bn(bl2, "content", jSONObject.toString());
                    try {
                        z.em(z.dx(35, bl2, userId));
                        cv.l++;
                        return;
                    } catch (Exception e3) {
                        e = e3;
                        cv.m++;
                        e.printStackTrace();
                        return;
                    }
                } catch (Exception e4) {
                    e4.printStackTrace();
                    cv.m++;
                    return;
                }
            default:
                return;
        }
    }

    @Override
    public final synchronized boolean handleMessage(Message message) {
        synchronized (this) {
            this.b.add(message);
            if (!this.d) {
                this.d = true;
                k();
            }
        }
        return true;
        return true;
    }

    public final void j(SoulSendMessageJson soulSendMessageJson) {
        Object dx = z.dx(soulSendMessageJson.getType(), soulSendMessageJson.getData(), soulSendMessageJson.getUserID());
        if (dx != null) {
            if (soulSendMessageJson.getImMessage() != null) {
                String userID = soulSendMessageJson.getUserID();
                synchronized (this) {
                    this.c.add(userID);
                    if (!this.e) {
                        this.e = true;
                        l();
                    }
                }
            }
            if (!TextUtils.isEmpty(soulSendMessageJson.getKey())) {
                if (y.by.getDb() != null) {
                    if (b.e(7, soulSendMessageJson.getUserID() + r.g.a(soulSendMessageJson.getKey())) == null) {
                        b.k(soulSendMessageJson.getUserID() + r.g.a(soulSendMessageJson.getKey()), 7, "", "");
                    } else {
                        return;
                    }
                } else {
                    return;
                }
            }
            z.el(dx);
        }
    }

    public final synchronized void k() {
        Message message = (Message) this.b.peek();
        if (message != null) {
            Object obj = message.getData().get("key");
            if (obj != null) {
                if (obj instanceof JsonHookDownPostMessage) {
                    JsonHookDownPostMessage jsonHookDownPostMessage = (JsonHookDownPostMessage) obj;
                    g.c(y.by.getActivity(), jsonHookDownPostMessage.getUrl(), jsonHookDownPostMessage.getName());
                }
                if (obj instanceof JsonOnlineState) {
                    g((JsonOnlineState) obj);
                } else if (obj instanceof SoulSendMessageJson) {
                    j((SoulSendMessageJson) obj);
                } else if (obj instanceof JsonHomepage) {
                    f((JsonHomepage) obj, message.getData().getBoolean("isTip"), message.getData().getInt("type"));
                } else if (obj instanceof JsonSoulAutoMessage) {
                    h((JsonSoulAutoMessage) obj);
                } else if (obj instanceof JsonSoulPlanet) {
                    i((JsonSoulPlanet) obj);
                }
            }
            this.b.poll();
            k();
        } else {
            this.d = false;
        }
    }

    public final synchronized void l() {
        String str = (String) this.c.peek();
        if (!TextUtils.isEmpty(str)) {
            JsonHookStatic jsonHookStatic = y.by;
            if (jsonHookStatic.getDb() != null) {
                ChatLogDao chatLogDao = jsonHookStatic.getDb().p;
                chatLogDao.getClass();
                g gVar = new g(chatLogDao);
                gVar.l(ChatLogDao.Properties.UserId.f(str), new i[0]);
                Iterator it = gVar.j().iterator();
                while (it.hasNext()) {
                    b bVar = (b) it.next();
                    Object dy = z.dy(bVar.b, bVar.c);
                    if (dy != null) {
                        z.eo(dy);
                        y.by.getDb().h(bVar);
                    }
                }
            }
            this.c.poll();
            l();
        } else {
            this.e = false;
        }
    }
}
